package com.tech.cloudapp.controller;

import com.tech.cloudapp.db.service.UserAnswerResultService;
import com.tech.cloudapp.model.CommonResponseDO;
import com.tech.cloudapp.po.UserAnswerResultParamPO;
import com.tech.cloudapp.util.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Validation;
import java.util.List;

@RestController
@RequestMapping("/user-answer-result")
public class UserAnswerResultController {

    @Autowired
    private UserAnswerResultService userAnswerResultServiceImpl;

    @PostMapping("/get")
    public CommonResponseDO getResult(@RequestBody UserAnswerResultParamPO userAnswerResultParamPO)
    {
        ValidatorUtils.validate(userAnswerResultParamPO);
        UserAnswerResultParamPO.UserAnswerResultPO result = userAnswerResultServiceImpl.getResult(userAnswerResultParamPO);
        return CommonResponseDO.success(result);
    }

    @PostMapping("/scorelist")
    public CommonResponseDO scoreRange()
    {
        List<UserAnswerResultParamPO.UserScoreSortResultPO> scores = userAnswerResultServiceImpl.getScores();
        return CommonResponseDO.success(scores);
    }
}
